#ifndef COORDSTRANSFORMER_H
#define COORDSTRANSFORMER_H

#include <stack>
#include <wx/geometry.h>
#include "Common/Common.h"

class CoordsTransformer {
public:
	CoordsTransformer();
	~CoordsTransformer();

	void Resize( int width, int height );

	cmn::Transform GetCamera() const;
	void SetCamera( const cmn::Transform& camera );

	void Push();
	void Pop();
	void Load( const cmn::Matr4& model );
	void Mult( const cmn::Matr4& model );

	cmn::Vec2 ScreenToWorld( const wxPoint& screen ) const;
	wxPoint WorldToScreen( const cmn::Vec2& world ) const;

private:
	void Frustum( float left, float right, float top, float bottom );

	cmn::Vec4 WorldToCam( const cmn::Vec4& world ) const;
	cmn::Vec4 CamToProjecion( const cmn::Vec4& cam ) const;
	wxPoint ProjecionToScreen( const cmn::Vec4& projecion ) const;

	cmn::Vec4 ScreenToProjecion( const wxPoint& screen ) const;
	cmn::Vec4 ProjecionToCam( const cmn::Vec4& projecion ) const;
	cmn::Vec4 CamToWorld( const cmn::Vec4& cam ) const;

private:
	std::stack<cmn::Matr4> m_matrStack;

	cmn::Matr4 m_modelMatr;
	cmn::Matr4 m_projectionMatr;

	int m_width;
	int m_height;

	cmn::Transform m_camera;
};

#endif
